/****************************************************************************** 
 * LPC24xx Standard Peripheral Library
 * Version:  1.0.0
 * 
 *  Copyright (C) 2012  Timothy Gack
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA 
 *******************************************************************************
 * Pin connect - Pin selection tables of register use.
 *                From: LPC24xx User Manual (UM10237.pdf) 
 *                      Chapter 9
 *
 *            LPC2458 Functions LPC2420 Functions LPC2460/68  Functions LPC2478
 *                    not               not                   not
 *                    available         available             available
 * - PINSEL0  9-130   -         9-130   -         9-130       -         9-130
 * - PINSEL1  9-131   -         9-131   -         9-131       -         9-131
 * - PINSEL2  9-132   LCD       9-132   Ethernet  9-132       LCD       9-132
 * -                                    LCD
 * - PINSEL3  9-133   LCD       9-133   LCD       9-133       LCD       9-133
 * - PINSEL4  9-134   LCD       9-135   CAN,LCD   9-135       LCD       9-135
 * - PINSEL5  9-136   -         9-137   -         9-137       -         9-137
 * - PINSEL6  9-138   -         9-138   -         9-138       -         9-138
 * - PINSEL7  9-139   -         9-140   -         9-140       -         9-140
 * - PINSEL8  -       -         9-141   -         9-141       -         9-141
 * - PINSEL9  9-142   LCD       9-143   LCD       9-143       -         9-143
 * - PINSEL10 9-144   -         9-144   -         9-144       -         9-144
 * - PINSEL11 -       -         -       -         -           -         9-145
 *
 *  The pin connect block allows selected pins of the microcontroller to have
 *  more than one function. Configuration registers control the multiplexers to
 *  allow connection between the pin and the on chip peripherals.
 *
 *  Peripherals should be connected to the appropriate pins prior to being
 *  activated, and prior to any related interrupt(s) being enabled. Activity of
 *  any enabled peripheral function that is not mapped to a related pin should
 *  be considered undefined.
 *
 *  Selecting a single function on a port pin completely excludes all other 
 *  functions available on the same pin.
 *******************************************************************************/
#ifndef _LPC24XX_PINCONNECT_H_
#define _LPC24XX_PINCONNECT_H_


#include "lpc24xx_std_includes.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef enum _PINFUNCTION_ 
{
  PINFN_0=0, 
  PINFN_1, 
  PINFN_2, 
  PINFN_3
}PINFUNCTION;

typedef enum _ETM_FLAG_ 
{
  ETM_DISABLE=0, 
  ETM_ENABLE
}ETM_FLAG;

typedef enum _LCD_PORTEN_FLAG_
{
  LCD_PORT_DISABLED=0,
  LCD_PORT_ENABLED
}LCD_PORTEN_FLAG;

typedef enum _LCD_MODE_
{
  LCDMODE_4BIT_MONO_STN_SINGLE=0,
  LCDMODE_8BIT_MONO_STN_SINGLE=1,
  LCDMODE_4BIT_MONO_STN_DUAL=2,
  LCDMODE_COLOR_STN_DUAL=3,
  LCDMODE_TFT_12BIT_444=4,
  LCDMODE_TFT_16BIT_565=5,
  LCDMODE_TFT_16BIT_1555=6,
  LCDMODE_TFT_24BIT = 7
}LCD_MODE;

typedef union _PINSEL_TYPE_
{
  uint32_t value;
  struct _PINSEL_TYPE_BITFIELDS
  {
    unsigned sb1_0 : 2;
    unsigned sb3_2 : 2;
    unsigned sb5_4 : 2;
    unsigned sb7_6 : 2;
    unsigned sb9_8 : 2;
    unsigned sb11_10 : 2;
    unsigned sb13_12 : 2;
    unsigned sb15_14 : 2;
    unsigned sb17_16 : 2;
    unsigned sb19_18 : 2;
    unsigned sb21_20 : 2;
    unsigned sb23_22 : 2;
    unsigned sb25_24 : 2;
    unsigned sb27_26 : 2;
    unsigned sb29_28 : 2;
    unsigned sb31_30 : 2;
  }bits;
}PINSEL_TYPE, *LP_PINSEL_TYPE;

typedef union _PINSEL10_TYPE_
{
  uint32_t value;
  struct _PINSEL10_TYPE_BITFIELDS
  {
    unsigned RESERVED0 : 2;
    unsigned gpio_trace : 1;
    unsigned RESERVED1 : 29;
  }bits;
}PINSEL10_TYPE, *LP_PINSEL10_TYPE;


typedef union _PINSEL11_TYPE_
{
  uint32_t value;
  struct _PINSEL11_TYPE_BITFIELDS
  {
    unsigned lcdpe : 1;
    unsigned lcdm : 3;
    unsigned RESERVED1 : 28;
  }bits;
}PINSEL11_TYPE, *LP_PINSEL11_TYPE;


typedef enum _PINMODE_
{
  PINMODE_PULLUP = 0,
  PINMODE_RESERVED,
  PINMODE_NO_RESISTOR,
  PINMODE_PULLDOWN
}PINMODE;

typedef union _PINMODE_TYPE_
{
  uint32_t value;
  struct _PINMODE_TYPE_BITFIELDS
  {
    unsigned mb1_0 : 2;
    unsigned mb3_2 : 2;
    unsigned mb5_4 : 2;
    unsigned mb7_6 : 2;
    unsigned mb9_8 : 2;
    unsigned mb11_10 : 2;
    unsigned mb13_12 : 2;
    unsigned mb15_14 : 2;
    unsigned mb17_16 : 2;
    unsigned mb19_18 : 2;
    unsigned mb21_20 : 2;
    unsigned mb23_22 : 2;
    unsigned mb25_24 : 2;
    unsigned mb27_26 : 2;
    unsigned mb29_28 : 2;
    unsigned mb31_30 : 2;
  }bits;
}PINMODE_TYPE, *LP_PINMODE_TYPE;

/* Pin Connect Block */
#define PINSEL0 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x00))
#define PINSEL1 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x04))
#define PINSEL2 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x08))
#define PINSEL3 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x0C))
#define PINSEL4 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x10))
#define PINSEL5 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x14))
#define PINSEL6 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x18))
#define PINSEL7 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x1C))
#define PINSEL8 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x20))
#define PINSEL9 (*(volatile PINSEL_TYPE *)(PINSEL_BASE_ADDR + 0x24))
#define PINSEL10 (*(volatile PINSEL10_TYPE *)(PINSEL_BASE_ADDR + 0x28))
#define PINSEL11 (*(volatile PINSEL11_TYPE *)(PINSEL_BASE_ADDR + 0x2C))

#define PINMODE0 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x40))
#define PINMODE1 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x44))
#define PINMODE2 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x48))
#define PINMODE3 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x4C))
#define PINMODE4 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x50))
#define PINMODE5 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x54))
#define PINMODE6 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x58))
#define PINMODE7 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x5C))
#define PINMODE8 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x60))
#define PINMODE9 (*(volatile PINMODE_TYPE *)(PINSEL_BASE_ADDR + 0x64))


#ifdef __cplusplus
}
#endif

#endif